package gugu.services.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import gugu.domain.Survey;
import gugu.domain.SurveyTypeEnum;
import gugu.domain.User;
import gugu.services.dao.SurveyDao;

@Repository("surveyDaoMongo")
public class SurveyDaoMongoImpl extends CrudDaoMongoImpl<Survey> implements SurveyDao {
	
	private static final Log LOGGER = LogFactory.getLog(MongoTemplate.class);

	@Resource
	private MongoOperations mongoOpts;

	@Override
	public List<Survey> findByOwner(User owner) {
		return mongoOpts.find(
				new Query(Criteria.where("owner.$id").is(
						new ObjectId(owner.getId()))), Survey.class);
	}

}
